package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Caringwelfare.BenefitActivity;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.Re_Servlet;
import com.example.myapplication.ShuJu.WelfareclassificationBean;
import com.example.myapplication.library.LibraryMainActivity;

import java.util.List;

public class WelfareclassificationApter  extends  RecyclerView.Adapter<WelfareclassificationApter.MyServer>{
    private Context context ;
    private List<WelfareclassificationBean.DataBean> list;
    private View view;
    private FragmentManager fragmentManager ;

    public WelfareclassificationApter(Context context, List<WelfareclassificationBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public WelfareclassificationApter.MyServer onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充试图
        view = LayoutInflater.from(context).inflate(R.layout.item_sever,null);
        return new WelfareclassificationApter.MyServer(view);
    }

    @Override
    public void onBindViewHolder(@NonNull WelfareclassificationApter.MyServer holder, int position) {
        Glide.with(context).load("http://124.93.196.45:10001"+list.get(position).getImgUrl()).into(holder.sever_tv_img);
        holder.sever_iv_text.setText(list.get(position).getName());
        //点击图标进入列表
        holder.sever_tv_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BenefitActivity.class);
                intent.putExtra("listID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class  MyServer extends RecyclerView.ViewHolder{


        private final TextView sever_iv_text;
        private final ImageView sever_tv_img;

        public MyServer(@NonNull View itemView) {
            super(itemView);
            sever_iv_text = itemView.findViewById(R.id.sever_iv_text);
            sever_tv_img = itemView.findViewById(R.id.sever_tv_img);
        }
    }
}
